package com.heima.controller;

import com.heima.pojo.vo.OrderPartnerVo;
import com.heima.service.OrderService;
import com.heima.utils.PageResult;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;


/**
 * @author 赵超
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/order-service/report")
public class ReportController {
    private final OrderService orderService;

    @GetMapping("/orderCount")
    public String orderCount(Integer partnerId, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime start, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime end) {
        return orderService.orderCount(partnerId, start, end);
    }

    @GetMapping("/orderAmount")
    public BigDecimal orderAmount(Integer partnerId, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime start, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime end) {
        return orderService.orderAmount(partnerId, start, end);
    }

    @GetMapping("/totalBill")
    public BigDecimal totalBill(Integer partnerId, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime start, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime end) {
        return orderService.totalBill(partnerId, start, end);
    }

    @GetMapping("/partnerCollect")
    public PageResult<OrderPartnerVo> partnerCollect(
            String partnerName,
            Integer pageIndex,
            Integer pageSize,
            @DateTimeFormat(pattern = "yyyy-MM-dd")
            LocalDate start,
            @DateTimeFormat(pattern = "yyyy-MM-dd")
            LocalDate end) {

        return orderService.query(partnerName, pageIndex, pageSize, start, end);
    }
}
